package redisson.rest.queue;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.redisson.codec.Kryo5Codec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import cn.com.dzpjpt.rsx.entity.vo.RpaProbeMsgOut;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("queue")
public class QueueProducer {

	@Autowired
	RedissonClient redissonClient;

	@GetMapping("send")
	public String send() {

		ThreadLocalRandom random = ThreadLocalRandom.current();
		String str = "test:queue:%s";

		RQueue<Object> queue = redissonClient.getQueue(String.format(str, "axxc"));
		int nextInt = random.nextInt(5, 10);
		for (int i = 0; i < nextInt; i++) {
			Map<Object, Object> map = new HashMap<>();
			map.put("cc", "cc");
			map.put("i", i);
			queue.addAsync(map);
		}

		return new String("发送Queue消息成功!");
	}

	@GetMapping("send2")
	public String send2() {
		String str = "rpa:probestart";
		RQueue<String> queue = redissonClient.getQueue(str);
		RpaProbeMsgOut out = new RpaProbeMsgOut();
		out.setAreaType("1");
		out.setMaintenanceSign("Y");
		out.setXzqhjm("11");

		String jsonString = JSONObject.toJSONString(out);
		queue.add(jsonString);

		return new String("发送Queue消息成功!");
	}

}
